package cn.yunyichina.provider.hisiface.http;

import java.io.InputStream;
import java.util.Properties;

/**
 * HttpServer 配置
 * 
 * @author zhou
 *
 */
public class HttpServerConfig {

	private static final HttpServerConfig config = new HttpServerConfig();
	
	private HttpServerConfig() {
		
	}
	
	public static HttpServerConfig getConfig() {
		return config;
	}
	
	/* 是否采用ssl连接 */
	private boolean ssl;
	
	/* 监听端口 */
	private int port;
	
	/* ssl证书路径 */
	private String sslPath;
	
	/* ssl密码 */
    private String sslPassword;
	
	 /* 是否需要验证客户端的证书 */
    private boolean needClientAuth;
    
    /* 是否开启http长连接 */
    private boolean keepAlive;
    
    private int nThreads;
    
    /* 是否开启免签名验证（生产环境关闭off） */
    private String noAuthSwitch;

	public boolean isSsl() {
		return ssl;
	}

	public int getPort() {
		return port;
	}

	public String getSslPath() {
		return sslPath;
	}
	
	public String getSslPassword() {
		return sslPassword;
	}
	
	public boolean isNeedClientAuth() {
		return needClientAuth;
	}
	
	public boolean isKeepAlive() {
		return keepAlive;
	}
	
	public int getnThreads() {
		return nThreads;
	}
	
	public String getNoAuthSwitch() {
		return noAuthSwitch;
	}
	
	public void initHttpConfig() throws Exception {
		try (InputStream is = HttpServerConfig.class.getClassLoader().getResourceAsStream("conf/httpserver.properties")) {
			Properties pro = new Properties();
	        pro.load(is);
	        this.ssl = Boolean.parseBoolean(pro.getProperty("httpserver.ssl", "true"));
	        this.port = Integer.parseInt(pro.getProperty("httpserver.port"));
	        this.sslPath = pro.getProperty("httpserver.sslpath");
	        this.sslPassword = pro.getProperty("httpserver.sslpassword");
	        this.needClientAuth = Boolean.parseBoolean(pro.getProperty("httpserver.needclientauth", "false"));
	        this.keepAlive = Boolean.parseBoolean(pro.getProperty("httpserver.keepalive", "true"));
	        this.nThreads = Integer.parseInt(pro.getProperty("httpserver.nthreads", "100"));
	        this.noAuthSwitch = pro.getProperty("noauth.switch", "off");
		}
	}
}
